package com.hbu.product.hbumallproduct.web;

import com.hbu.product.hbumallproduct.service.CategoryService;
import com.hbu.product.hbumallproduct.vo.Catelog2VO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @ProjectName: hbu-mall
 * @Package: com.hbu.product.hbumallproduct.web
 * @ClassName: IndexController
 * @Author: zxh
 * @Description:
 * @Date: 2022/12/6 21:13
 * @Version: 1.0
 */
@Controller
@AllArgsConstructor
public class IndexController {

    private CategoryService categoryService;

    @GetMapping({"/", "index.html"})
    public String indexPage(Model model) {
        model.addAttribute("categorys", categoryService.getFirstLevelCategorys());
        return "index";
    }

    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String, List<Catelog2VO>> getCatalogJson() {
         return categoryService.getCatalogJson();
    }

}
